package com.weapons.week0903_weapons.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.weapons.week0903_weapons.R;
import com.weapons.week0903_weapons.bean.ImageBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Author: Administrator
 * Created by Administrator on 2016/7/20.
 */
public class ImageRecycleAdapter extends RecyclerView.Adapter<ImageRecycleAdapter.ImageHolder>{
    private List<ImageBean.ItemBean> mDatas;
    private Context mContext;
    public ImageRecycleAdapter(List<ImageBean.ItemBean> mDatas, Context mContext) {
        this.mDatas = mDatas;
        this.mContext = mContext;
    }
    public ImageHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_image,null);
        return new ImageHolder(view);
    }
    public void onBindViewHolder(ImageHolder holder, int position) {
        holder.tv.setText(mDatas.get(position).getTitle());
        Picasso.with(mContext).load(mDatas.get(position).getImage_arr().get(0))
        .into(holder.iv);
    }
    public int getItemCount() {
        Log.i("lala",mDatas.size()+"sdfs");
        return mDatas == null? 0:mDatas.size();
    }
    class ImageHolder extends RecyclerView.ViewHolder{
        private ImageView iv;
        private TextView tv;
        public ImageHolder(View itemView) {
            super(itemView);
            iv = (ImageView) itemView.findViewById(R.id.itemImage_iv);
            tv = (TextView) itemView.findViewById(R.id.itemImage_tv);
        }
    }
}
